package com.gilda.fmupdate;

import android.util.Log;

public class MainA {
	
	public native int writeDataToFile(int data1, int data2);
	public native int isFmOn();
	static {
		System.loadLibrary("fmupdatelib");
	}
	
	private static final String TAG = "FMLauncher";
	private boolean mFMLauncherState = false;
	private int initChannel = 8750;
	
	private static MainA instance;
	public static MainA getInstance(){
		if(instance == null)
			instance = new MainA();
		return instance;
	}

	/**
	 * 打开FM
	 * @return
	 */
	public boolean setFMLauncherOpen(){
		writeDataToFile(0, initChannel);
		mFMLauncherState = getFMLauncherStatus();
		return mFMLauncherState ;
	}
	
	/**
	 * 关闭FM
	 * @return
	 */
	public boolean setFMLauncherClose(){
		writeDataToFile(1, 0);
		mFMLauncherState = getFMLauncherStatus();
		return mFMLauncherState;
	}
	
	/**
	 * 获取FM当前状态
	 * @return
	 */
	public boolean getFMLauncherStatus(){
		int ret_status = 0;
		ret_status = isFmOn();
		Log.i(TAG, "getFMLauncherStatus：ret_status=" + ret_status);
		if(ret_status == 0){
			mFMLauncherState = false;
			Log.i(TAG, "getFMLauncherStatus--false");
		}else if(ret_status == 1){
			mFMLauncherState = true;
			Log.i(TAG, "getFMLauncherStatus--true");
		}
		return mFMLauncherState;
	}
	
	/**
	 * 设置频率
	 * @param value
	 * @return
	 */
	public int setProgressValue(float value){
		Log.i(TAG, "setProgressValue：value=" + value);
        float showText = value*100;
        int data = (int)showText;
        int poenOrClose = mFMLauncherState == true ? 0 : 1;
        int result = writeDataToFile(poenOrClose, data);
		return result;
	}
}
